-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
3,475 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
require('../')() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const error = require('../templates/error'); | ||
const spawn = require('child_process').spawnSync; | ||
|
||
module.exports = (args) => { | ||
// reliant on portals starting with p, services starting with s, etc... | ||
if (args.a) { | ||
switch (args.l) { | ||
case '-services': | ||
spawn(`npm run build:all-services`, [], { shell: true, stdio: 'inherit' }); | ||
break; | ||
case '-portals': | ||
spawn(`npm run build:all-portals`, [], { shell: true, stdio: 'inherit' }); | ||
break; | ||
case '-widgets': | ||
if (args.p) { | ||
spawn(`npm run build:all-widgets -portal=${args.p}`, [], { shell: true, stdio: 'inherit' }); | ||
} else { | ||
error(`Please specify a -portal flag to build all widgets`, true); | ||
} | ||
break; | ||
case '-libraries': | ||
spawn(`npm run build:all-libraries`, [], { shell: true, stdio: 'inherit' }); | ||
break; | ||
} | ||
} else if (args.s) { | ||
spawn(`npm run build:service -service=${args.s}`, [], { shell: true, stdio: 'inherit' }); | ||
} else if (args.l) { | ||
spawn(`npm run build:library -library=${args.l}`, [], { shell: true, stdio: 'inherit' }); | ||
} else if (args.p) { | ||
if (args.w) { | ||
spawn(`npm run build:widget -portal=${args.p} -widgetId=${args.w}`, [], { shell: true, stdio: 'inherit' }); | ||
} else if (args.i) { | ||
spawn(`npm run build:internal-resource -portal=${args.p} -internalResource=${args.i}`, [], { shell: true, stdio: 'inherit' }); | ||
} else { | ||
spawn(`npm run build:portal -portal=${args.p}`, [], { shell: true, stdio: 'inherit' }); | ||
} | ||
} else { | ||
error('Please specify either a -portal(-p), -service(-s), -library(-l), or -all flag to build asset. See cb-dev-kit build --help for more info.', true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const error = require('../templates/error'); | ||
const spawn = require('child_process').spawnSync; | ||
|
||
module.exports = (args) => { | ||
// reliant on portals starting with p, services starting with s, etc... | ||
if (args.p) { | ||
let script = `npm run start:clearblade-hot-reload -portal=${args.p}`; | ||
if (args.m) { | ||
script += ` -messagePort=${args.m}` | ||
} | ||
if (args.n) { | ||
script += ` -noSSL=${args.n}` | ||
} | ||
if (args.c) { | ||
script += ` -caPath=${args.c}` | ||
} | ||
spawn(script, [], { shell: true, stdio: 'inherit' }); | ||
} else { | ||
error('Please specify either a -portal(-p) flag start hot reload. See cb-dev-kit build --help for more info.', true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const error = require('../templates/error'); | ||
const { createFile, consts: { WIDGETS, INTERNAL_RESOURCES, DATASOURCES, SERVICES, LIBRARIES } } = require('../utils/generateSrcFiles'); | ||
|
||
module.exports = (args) => { | ||
// reliant on portals starting with p, services starting with s, etc... | ||
if (args.p) { | ||
if (args.w) { | ||
createFile(WIDGETS, args); | ||
} else if (args.i) { | ||
createFile(INTERNAL_RESOURCES, args); | ||
} | ||
// else if (args.d) { | ||
// createFile(DATASOURCES, args); | ||
// } | ||
else { | ||
error('Please specify either a -widgetId(-w) or -internalResource(-i) flag in addition to -portal to create asset. See cb-dev-kit create --help for more info.', true); | ||
} | ||
} else if (args.s) { | ||
createFile(SERVICES, args); | ||
} else if (args.l) { | ||
createFile(LIBRARIES, args); | ||
} else { | ||
error('Please specify either a -portal(-p), -service(-s), or -library(-l) flag to create asset. See cb-dev-kit create --help for more info.', true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
if (process.env.cwd) { | ||
process.chdir(process.env.cwd); | ||
} | ||
|
||
const widgetGenerator = require('../generators/widget'); | ||
const internalResourceGenerator = require('../generators/internalResource'); | ||
// const datasourceGenerator = require('../generators/datasource'); | ||
const codeServiceGenerator = require('../generators/codeService'); | ||
const libraryGenerator = require('../generators/library'); | ||
|
||
const shell = require('shelljs'); | ||
|
||
module.exports = (plop) => { | ||
plop.setActionType('createFile', function (answers, config, plop) { | ||
let cmd = `cb-dev-kit create`; | ||
for (const flag in answers) { | ||
cmd += ` -${flag}=${answers[flag]}`; | ||
} | ||
shell.exec(cmd) | ||
}); | ||
|
||
plop.setGenerator('widget', widgetGenerator); | ||
plop.setGenerator('internalResource', internalResourceGenerator); | ||
// plop.setGenerator('datasource', datasourceGenerator); | ||
plop.setGenerator('service', codeServiceGenerator); | ||
plop.setGenerator('library', libraryGenerator); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const menus = { | ||
main: ` | ||
cb-dev-kit [command] <options> | ||
Commands: | ||
init .................... initialize cb-dev-kit cli application, install packages, add scripts, add webpack configuration, and configure directory | ||
create .................. sets up an asset in src directory to be accessed by webpack for transpilation or clearblade-hot-reload(@clearblade/clearblade-hot-reload) | ||
build ................... builds an asset from src directory into its respective directory in the system | ||
clearblade-hot-reload ... start clearblade-hot-reload server to hot reload changes in portal in browser (@clearblade/clearblade-hot-reload) | ||
generate ................ launch generator to walk through creating an asset in src directory | ||
version ................. show package version | ||
help .................... show help menu. Followed by a command name shows help for the command`, | ||
|
||
init: ` | ||
cb-dev-kit init <options> | ||
initialize cb-dev-kit cli application, install packages, add scripts, add webpack configuration, and configure directory`, | ||
|
||
create: ` | ||
cb-dev-kit create <options> | ||
sets up an asset in src directory to be accessed by webpack for transpilation or clearblade-hot-reload(@clearblade/clearblade-hot-reload) | ||
Options: | ||
-portal, -p .............. name of portal | ||
-widgetId, -w .......... ID of widget, source will include all available parsers | ||
-internalResource, -i .. name of internal resource | ||
-type, -t .............. (optional) file type of new source file. Options include js, jsx, ts, and tsx. Defaults to js. | ||
-service, -s ........ name of service | ||
-type, -t ......... (optional) file type of new source file. Options include js, jsx, ts, and tsx. Defaults to js. | ||
-library, -l ........ name of library | ||
-type, -t ......... (optional) file type of new source file. Options include js, jsx, ts, and tsx. Defaults to js.`, | ||
|
||
build: ` | ||
cb-dev-kit build <options> | ||
builds an asset from src directory into its respective directory in the system | ||
Options: | ||
-all, -a ................. build all assets in src directory | ||
-all-services ............ build all services in src directory | ||
-all-libraries ........... build all libraries in src directory | ||
-all-portals ............. build all portals in src directory | ||
-all-widgets ............. build all widgets in a portal in src directory | ||
-portal, -p ............ name of portal | ||
-portal, -p .............. name of portal | ||
-widgetId, -w .......... (optional) ID of widget | ||
-internalResource, -i .. (optional) name of internal resource including extension | ||
-service, -s ........ name of service | ||
-library, -l ........ name of library`, | ||
|
||
['clearblade-hot-reload']: ` | ||
cb-dev-kit clearblade-hot-reload <options> | ||
Options: | ||
-portal, -p ............. name of portal | ||
-messagePort, -m ...... (optional) messaging port console is listening to, defaults to 1883 | ||
-noSSL, -n ............ (optional) if pointing hotReload at a local platform, please set -noSSL to true | ||
-caPath, -c ........... (optional) if pointing at a production system and your certificate authority is not DigiCert, you must use -caPath to provide the absolute path of your CA` | ||
|
||
} | ||
|
||
module.exports = (args) => { | ||
const subCmd = args._[0] === 'help' | ||
? args._[1] | ||
: args._[0] | ||
|
||
console.log(menus[subCmd] || menus.main) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const shell = require('shelljs'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const error = require('../templates/error'); | ||
const initConfigs = require('../utils/initConfigurations'); | ||
|
||
module.exports = () => { | ||
if (!fs.existsSync(path.resolve(`package.json`))) { | ||
shell.exec(`npm init -y`); | ||
}; | ||
|
||
if (!fs.existsSync(path.resolve(`node_modules`))) { | ||
fs.appendFileSync('.gitignore', '\nnode_modules'); | ||
}; | ||
|
||
const packageJson = JSON.parse(fs.readFileSync(path.resolve(`package.json`).toString())); | ||
|
||
const modifiedPackageJson = { | ||
...packageJson, | ||
scripts: { | ||
...initConfigs.scripts, | ||
...packageJson.scripts, | ||
}, | ||
devDependencies: { | ||
...initConfigs.packages, | ||
...packageJson.devDependencies | ||
}, | ||
babel: { | ||
...packageJson.babel, | ||
...initConfigs.babel | ||
}, | ||
jest: { | ||
...packageJson.jest, | ||
...initConfigs.jest | ||
} | ||
} | ||
|
||
fs.writeFileSync(path.resolve(`package.json`), JSON.stringify(modifiedPackageJson), function (err) { | ||
if (err) error(err); | ||
}); | ||
|
||
shell.exec('npm install'); | ||
|
||
fs.mkdirSync(path.resolve(`./cb-dev-kit`)); | ||
|
||
const templates = fs.readdirSync(path.join(__dirname, '../templates')); | ||
for (const file in templates) { | ||
const content = fs.readFileSync(path.join(__dirname, `../templates/${templates[file]}`).toString()); | ||
fs.writeFileSync(path.resolve(`./cb-dev-kit/${templates[file]}`), content, function (err) { | ||
if (err) error(err); | ||
}); | ||
} | ||
|
||
if (!fs.existsSync(path.resolve(`./src`))) { | ||
fs.mkdirSync(path.resolve(`./src`)); | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { version } = require('../package.json') | ||
|
||
module.exports = (args) => { | ||
console.log(`v${version}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { getServices } = require('../utils/getAssets'); | ||
|
||
module.exports = { | ||
description: `add a code service to the src directory`, | ||
prompts: [{ | ||
type: 'list', | ||
name: 'service', | ||
message: 'Select code service', | ||
choices: getServices() | ||
}, { | ||
type: 'list', | ||
name: 'type', | ||
message: 'Select file type', | ||
choices: ['js', 'ts'] | ||
}], | ||
actions: [{ | ||
type: 'createFile' | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { getPortals, getDatasources } = require('../utils/getAssets'); | ||
|
||
module.exports = { | ||
description: `add a datasource parser to the src directory`, | ||
prompts: [{ | ||
type: 'list', | ||
name: 'portal', | ||
message: 'Select portal', | ||
choices: getPortals() | ||
}, { | ||
type: 'list', | ||
name: 'datasource', | ||
message: 'Select datasource', | ||
choices: (name) => getDatasources(name.portal) | ||
}, { | ||
type: 'list', | ||
name: 'type', | ||
message: 'Select file type', | ||
choices: ['js', 'ts'] | ||
}], | ||
actions: [{ | ||
type: 'createFile' | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { getPortals, getInternalResources } = require('../utils/getAssets'); | ||
|
||
module.exports = { | ||
description: `add an internal resource to the src directory`, | ||
prompts: [{ | ||
type: 'list', | ||
name: 'portal', | ||
message: 'Select portal', | ||
choices: getPortals() | ||
}, { | ||
type: 'list', | ||
name: 'intResource', | ||
message: 'Select internal resource', | ||
choices: (name) => getInternalResources(name.portal) | ||
}, { | ||
type: 'list', | ||
name: 'type', | ||
message: 'Select file type', | ||
choices: ['js', 'ts', 'tsx', 'jsx'] | ||
}], | ||
actions: [{ | ||
type: 'createFile' | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { getLibraries } = require('../utils/getAssets'); | ||
|
||
module.exports = { | ||
description: `add a library to the src directory`, | ||
prompts: [{ | ||
type: 'list', | ||
name: 'library', | ||
message: 'Select library', | ||
choices: getLibraries() | ||
}, { | ||
type: 'list', | ||
name: 'type', | ||
message: 'Select file type', | ||
choices: ['js', 'ts'] | ||
}], | ||
actions: [{ | ||
type: 'createFile' | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { getPortals, getWidgets } = require('../utils/getAssets'); | ||
|
||
module.exports = { | ||
description: `add a widget's parser(s) to the src directory`, | ||
prompts: [{ | ||
type: 'list', | ||
name: 'portal', | ||
message: 'Select portal', | ||
choices: getPortals() | ||
}, { | ||
type: 'list', | ||
name: 'widgetId', | ||
message: 'Select widget', | ||
choices: (name) => getWidgets(name.portal).map((widget) => { | ||
return { | ||
name: widget, | ||
value: widget.split('_').pop() | ||
} | ||
}) | ||
}, { | ||
type: 'list', | ||
name: 'type', | ||
message: 'Select file type', | ||
choices: ['js', 'jsx', 'ts', 'tsx'] | ||
}], | ||
actions: [{ | ||
type: 'createFile' | ||
}] | ||
} |
Oops, something went wrong.