diff --git a/package-lock.json b/package-lock.json index 3a76126..16c2545 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8479,7 +8479,9 @@ } }, "node_modules/@types/jsonld": { - "version": "1.5.13", + "version": "1.5.15", + "resolved": "https://registry.npmjs.org/@types/jsonld/-/jsonld-1.5.15.tgz", + "integrity": "sha512-PlAFPZjL+AuGYmwlqwKEL0IMP8M8RexH0NIPGfCVWSQ041H2rR/8OlyZSD7KsCVoN8vCfWdtWDBxX8yBVP+xow==", "license": "MIT" }, "node_modules/@types/keygrip": { @@ -8750,6 +8752,8 @@ }, "node_modules/@types/shexj": { "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@types/shexj/-/shexj-2.1.4.tgz", + "integrity": "sha512-/dcF8vT/CHseZxNTcWR+otf6018PACgHiKFukPYsxQCRppGZq0UcALMedZUUnj7IM4WOesFoERwJBhEw44d/VQ==", "dev": true, "license": "MIT" }, @@ -28740,6 +28744,7 @@ "version": "0.0.1-alpha.28", "license": "MIT", "dependencies": { + "@ldo/ldo": "^0.0.1-alpha.28", "@ldo/schema-converter-shex": "^0.0.1-alpha.24", "@shexjs/parser": "^1.0.0-alpha.24", "child-process-promise": "^2.2.1", @@ -28756,12 +28761,14 @@ "ldo": "dist/index.js" }, "devDependencies": { + "@ldo/cli": "^0.0.1-alpha.28", "@types/child-process-promise": "^2.2.2", "@types/ejs": "^3.1.1", "@types/fs-extra": "^9.0.13", "@types/jest": "^27.0.3", + "@types/jsonld": "^1.5.15", "@types/prompts": "^2.4.9", - "@types/shexj": "2.1.4", + "@types/shexj": "^2.1.4", "copyfiles": "^2.4.1", "jest": "^27.4.2", "rimraf": "^3.0.2", diff --git a/packages/cli/README.md b/packages/cli/README.md index 2200e69..e88f798 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -53,9 +53,20 @@ This will generate five files: - `./ldo/foafProfile.schema.ts` - `./ldo/foafProfile.context.ts` +## Creating a new project to distribure shapes + +Sometimes, you might want to distribute shapes to others. The easiest way to do that is to deploy them to NPM. The LDO CLI has an easy-to-use command for generating a standalone project just for your shapes. + +```bash +npx @ldo/cli create ./my-project +``` + +This script will generate a project with a place to put your shapes. Running `npm publish` will build the shapes and push to project to NPM for you. + ## API Details - [`init` command](https://ldo.js.org/api/cli/init/) - [`build` command](https://ldo.js.org/api/cli/build/) + - [`create` command](https://ldo.js.org/api/cli/create/) ``` ## Sponsorship diff --git a/packages/cli/example-init-placeholder/package.json b/packages/cli/example-init-placeholder/package.json new file mode 100644 index 0000000..f41a7f6 --- /dev/null +++ b/packages/cli/example-init-placeholder/package.json @@ -0,0 +1,11 @@ +{ + "name": "example-init", + "version": "1.0.0", + "description": "", + "keywords": [ + "" + ], + "author": "", + "license": "MIT", + "main": "./index.js" +} \ No newline at end of file diff --git a/packages/cli/package.json b/packages/cli/package.json index 3165265..a8b5899 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -15,7 +15,7 @@ "test": "jest --coverage", "prepublishOnly": "npm run test && npm run build", "lint": "eslint src/** --fix --no-error-on-unmatched-pattern", - "test:init": "rm -rf ./example-init && mkdir ./example-init && cd ./example-init && ../dist/index.js init", + "test:init": "rm -rf ./example-init && cp -R ./example-init-placeholder ./example-init && cd ./example-init && ../dist/index.js init", "test:create": "rm -rf ./example-create && ./dist/index.js create ./example-create" }, "repository": { @@ -29,18 +29,21 @@ }, "homepage": "https://github.com/o-development/ldobjects/tree/main/packages/cli#readme", "devDependencies": { + "@ldo/cli": "^0.0.1-alpha.28", "@types/child-process-promise": "^2.2.2", "@types/ejs": "^3.1.1", "@types/fs-extra": "^9.0.13", "@types/jest": "^27.0.3", + "@types/jsonld": "^1.5.15", "@types/prompts": "^2.4.9", - "@types/shexj": "2.1.4", + "@types/shexj": "^2.1.4", "copyfiles": "^2.4.1", "jest": "^27.4.2", "rimraf": "^3.0.2", "ts-jest": "^27.0.7" }, "dependencies": { + "@ldo/ldo": "^0.0.1-alpha.28", "@ldo/schema-converter-shex": "^0.0.1-alpha.24", "@shexjs/parser": "^1.0.0-alpha.24", "child-process-promise": "^2.2.1", diff --git a/packages/cli/src/create.ts b/packages/cli/src/create.ts index 808b990..8f04a1e 100644 --- a/packages/cli/src/create.ts +++ b/packages/cli/src/create.ts @@ -82,7 +82,7 @@ export async function create(directory: string) { // Init LDO load.text = "Initializing LDO"; - await init({ directory }); + await init(directory); // Add prepublish script await modifyPackageJson(directory, async (packageJson) => { diff --git a/packages/cli/src/init.ts b/packages/cli/src/init.ts index 98196a2..1d08ff4 100644 --- a/packages/cli/src/init.ts +++ b/packages/cli/src/init.ts @@ -8,19 +8,9 @@ const DEFAULT_SHAPES_FOLDER = "./.shapes"; const DEFAULT_LDO_FOLDER = "./.ldo"; const POTENTIAL_PARENT_DIRECTORIES = ["src", "lib", "bin"]; -export interface InitOptions { - directory?: string; -} - -export async function init(initOptions: InitOptions) { - // Install dependencies - await exec(`cd ${initOptions.directory} && npm install @ldo/ldo --save`); - await exec( - `cd ${initOptions.directory} && npm install @ldo/cli @types/shexj @types/jsonld --save-dev`, - ); - +export async function init(directory?: string) { // Find folder to save to - let parentDirectory = initOptions.directory!; + let parentDirectory = directory!; if (!parentDirectory) { parentDirectory = "./"; const allDirectories = ( @@ -40,6 +30,12 @@ export async function init(initOptions: InitOptions) { } } + // Install dependencies + await exec(`cd ${parentDirectory} && npm install @ldo/ldo --save`); + await exec( + `cd ${parentDirectory} && npm install @ldo/cli @types/shexj @types/jsonld --save-dev`, + ); + // Create "shapes" folder const shapesFolderPath = path.join(parentDirectory, DEFAULT_SHAPES_FOLDER); await fs.promises.mkdir(shapesFolderPath);