lincd-cli 0.2.79 → 0.2.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,9 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.buildPackage = exports.register = exports.createPackage = exports.startServer = exports.depCheck = exports.depCheckStaged = exports.checkImports = exports.createComponent = exports.createSetComponent = exports.createShape = exports.setNameVariables = exports.createOntology = exports.getLincdPackages = exports.buildAll = exports.developPackage = exports.warn = exports.createApp = void 0;
6
+ exports.executeCommandForPackage = exports.addCapacitor = exports.addLinesToFile = exports.executeCommandForEachPackage = exports.buildUpdated = exports.publishPackage = exports.publishUpdated = exports.buildPackage = exports.register = exports.createPackage = exports.buildApp = exports.startServer = exports.ensureEnvironmentLoaded = exports.depCheck = exports.depCheckStaged = exports.checkImports = exports.createComponent = exports.createSetComponent = exports.createShape = exports.setNameVariables = exports.createOntology = exports.getLincdPackages = exports.buildAll = exports.developPackage = exports.warn = exports.createApp = void 0;
16
7
  const chalk_1 = __importDefault(require("chalk"));
17
8
  const child_process_1 = require("child_process");
18
9
  const depcheck_1 = __importDefault(require("depcheck"));
@@ -21,12 +12,14 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
21
12
  const path_1 = __importDefault(require("path"));
22
13
  const utils_1 = require("./utils");
23
14
  const fs_1 = require("fs");
15
+ const find_nearest_package_json_1 = require("find-nearest-package-json");
16
+ // const config = require('lincd-server/site.webpack.config');
24
17
  var glob = require('glob');
25
18
  var variables = {};
26
19
  var open = require('open');
27
20
  var stagedGitFiles = require('staged-git-files');
28
- const find_nearest_package_json_1 = require("find-nearest-package-json");
29
- const createApp = (name, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
21
+ const webpack = require('webpack');
22
+ const createApp = async (name, basePath = process.cwd()) => {
30
23
  if (!name) {
31
24
  console.warn('Please provide a name as the first argument');
32
25
  }
@@ -46,16 +39,16 @@ const createApp = (name, basePath = process.cwd()) => __awaiter(void 0, void 0,
46
39
  // fs.copySync(path.join(__dirname, '..', 'defaults', 'app'), targetFolder);
47
40
  log("Creating new LINCD application '" + name + "'");
48
41
  //replace variables in some copied files
49
- yield replaceVariablesInFolder(targetFolder);
50
- let hasYarn = yield hasYarnInstalled();
42
+ await replaceVariablesInFolder(targetFolder);
43
+ let hasYarn = await hasYarnInstalled();
51
44
  let installCommand = hasYarn
52
45
  ? 'export NODE_OPTIONS="--no-network-family-autoselection" && yarn install'
53
46
  : 'npm install';
54
- yield (0, utils_1.execp)(`cd ${hyphenName} && ${installCommand}`, true).catch((err) => {
47
+ await (0, utils_1.execp)(`cd ${hyphenName} && ${installCommand}`, true).catch((err) => {
55
48
  console.warn('Could not install dependencies or start application');
56
49
  });
57
50
  log(`Your LINCD App is ready at ${chalk_1.default.blueBright(targetFolder)}`, `To start, run\n${chalk_1.default.blueBright(`cd ${hyphenName}`)} and then ${chalk_1.default.blueBright((hasYarn ? 'yarn' : 'npm') + ' start')}`);
58
- });
51
+ };
59
52
  exports.createApp = createApp;
60
53
  function logHelp() {
61
54
  (0, utils_1.execp)('yarn exec lincd help');
@@ -185,7 +178,7 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
185
178
  };
186
179
  let done = new Set();
187
180
  let results = [];
188
- let runStack = (stack) => __awaiter(this, void 0, void 0, function* () {
181
+ let runStack = async (stack) => {
189
182
  let runFunction = onBuildStack(stack, dependencies);
190
183
  let stackPromise;
191
184
  if (sync) {
@@ -204,7 +197,7 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
204
197
  }));
205
198
  }
206
199
  //wait till stack is completed
207
- let stackResults = yield stackPromise;
200
+ let stackResults = await stackPromise;
208
201
  results = results.concat(stackResults);
209
202
  //clear stack for next round
210
203
  stack = [];
@@ -281,7 +274,7 @@ function runOnPackagesGroupedByDependencies(lincdPackages, onBuildStack, onStack
281
274
  else {
282
275
  onStackEnd(dependencies, results.filter(Boolean));
283
276
  }
284
- });
277
+ };
285
278
  //starts the process
286
279
  runStack(startStack);
287
280
  }
@@ -347,7 +340,7 @@ function buildAll(options) {
347
340
  // log(stack);
348
341
  }
349
342
  (0, utils_1.debugInfo)('Now building: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
350
- return (pkg) => __awaiter(this, void 0, void 0, function* () {
343
+ return async (pkg) => {
351
344
  let command;
352
345
  let skipping = false;
353
346
  //if we're skipping builds until a certain package
@@ -409,7 +402,7 @@ function buildAll(options) {
409
402
  }
410
403
  return res;
411
404
  });
412
- });
405
+ };
413
406
  }, (dependencies) => {
414
407
  //if no more packages to build but we never started building...
415
408
  if (!building) {
@@ -507,8 +500,8 @@ function setVariable(name, replacement) {
507
500
  name = name.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
508
501
  variables[name] = replacement;
509
502
  }
510
- var replaceVariablesInFile = (filePath) => __awaiter(void 0, void 0, void 0, function* () {
511
- var fileContent = yield fs_extra_1.default.readFile(filePath, 'utf8').catch((err) => {
503
+ var replaceVariablesInFile = async (filePath) => {
504
+ var fileContent = await fs_extra_1.default.readFile(filePath, 'utf8').catch((err) => {
512
505
  console.warn(chalk_1.default.red('Could not read file ' + filePath));
513
506
  });
514
507
  if (fileContent) {
@@ -518,7 +511,7 @@ var replaceVariablesInFile = (filePath) => __awaiter(void 0, void 0, void 0, fun
518
511
  else {
519
512
  return Promise.resolve();
520
513
  }
521
- });
514
+ };
522
515
  var replaceCurlyVariables = function (string) {
523
516
  // var reg = new RegExp('\\$\\{'+key+'\\}','g');
524
517
  for (var key in variables) {
@@ -534,7 +527,7 @@ const camelCase = (str) => {
534
527
  }
535
528
  return str;
536
529
  };
537
- const createOntology = (prefix, uriBase, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
530
+ const createOntology = async (prefix, uriBase, basePath = process.cwd()) => {
538
531
  if (!prefix) {
539
532
  console.warn('Please provide a suggested prefix as the first argument');
540
533
  return;
@@ -555,7 +548,7 @@ const createOntology = (prefix, uriBase, basePath = process.cwd()) => __awaiter(
555
548
  let targetDataFile2 = path_1.default.join(targetFolder, '..', 'data', hyphenName + '.json.d.ts');
556
549
  fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package', 'src', 'data', 'example-ontology.json'), targetDataFile);
557
550
  fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package', 'src', 'data', 'example-ontology.json.d.ts'), targetDataFile2);
558
- yield replaceVariablesInFiles(targetFile, targetDataFile, targetDataFile2);
551
+ await replaceVariablesInFiles(targetFile, targetDataFile, targetDataFile2);
559
552
  log(`Prepared a new ontology data files in ${chalk_1.default.magenta(targetDataFile.replace(basePath, ''))}`, `And an ontology accessor file in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`);
560
553
  //if this is not a lincd app (but a lincd package instead)
561
554
  if (!sourceFolder.includes('frontend')) {
@@ -563,7 +556,7 @@ const createOntology = (prefix, uriBase, basePath = process.cwd()) => __awaiter(
563
556
  let indexPath = addLineToIndex(`import './ontologies/${hyphenName}';`, 'ontologies');
564
557
  log(`Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
565
558
  }
566
- });
559
+ };
567
560
  exports.createOntology = createOntology;
568
561
  const addLineToIndex = function (line, insertMatchString) {
569
562
  //import ontology in index
@@ -615,14 +608,12 @@ const replaceVariablesInFolder = function (folder) {
615
608
  const replaceVariablesInFilesWithRoot = function (root, ...files) {
616
609
  return replaceVariablesInFiles(...files.map((f) => path_1.default.join(root, f)));
617
610
  };
618
- const hasYarnInstalled = function () {
619
- return __awaiter(this, void 0, void 0, function* () {
620
- let version = (yield (0, utils_1.execPromise)('yarn --version').catch((err) => {
621
- console.log('yarn probably not working');
622
- return '';
623
- }));
624
- return version.toString().match(/[0-9]+/);
625
- });
611
+ const hasYarnInstalled = async function () {
612
+ let version = (await (0, utils_1.execPromise)('yarn --version').catch((err) => {
613
+ console.log('yarn probably not working');
614
+ return '';
615
+ }));
616
+ return version.toString().match(/[0-9]+/);
626
617
  };
627
618
  const ensureFolderExists = function (...folders) {
628
619
  let target;
@@ -674,7 +665,7 @@ function getSourceFolder(basePath = process.cwd()) {
674
665
  return path_1.default.join(basePath, 'src');
675
666
  }
676
667
  }
677
- const createShape = (name, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
668
+ const createShape = async (name, basePath = process.cwd()) => {
678
669
  let sourceFolder = getSourceFolder(basePath);
679
670
  let targetFolder = ensureFolderExists(sourceFolder, 'shapes');
680
671
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
@@ -683,7 +674,7 @@ const createShape = (name, basePath = process.cwd()) => __awaiter(void 0, void 0
683
674
  let targetFile = path_1.default.join(targetFolder, hyphenName + '.ts');
684
675
  fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'shape.ts'), targetFile);
685
676
  //replace variables in some of the copied files
686
- yield replaceVariablesInFiles(targetFile);
677
+ await replaceVariablesInFiles(targetFile);
687
678
  log(`Created a new shape class template in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`);
688
679
  //if this is NOT a lincd app (but a lincd package)
689
680
  let indexPath;
@@ -691,9 +682,9 @@ const createShape = (name, basePath = process.cwd()) => __awaiter(void 0, void 0
691
682
  indexPath = addLineToIndex(`import './shapes/${hyphenName}';`, 'shapes');
692
683
  log(`Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
693
684
  }
694
- });
685
+ };
695
686
  exports.createShape = createShape;
696
- const createSetComponent = (name, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
687
+ const createSetComponent = async (name, basePath = process.cwd()) => {
697
688
  let targetFolder = ensureFolderExists(basePath, 'src', 'components');
698
689
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
699
690
  //copy default shape file
@@ -703,12 +694,12 @@ const createSetComponent = (name, basePath = process.cwd()) => __awaiter(void 0,
703
694
  let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
704
695
  fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.scss'), targetFile2);
705
696
  //replace variables in some of the copied files
706
- yield replaceVariablesInFiles(targetFile, targetFile2);
697
+ await replaceVariablesInFiles(targetFile, targetFile2);
707
698
  let indexPath = addLineToIndex(`import './components/${hyphenName}';`, 'components');
708
699
  log(`Created a new set component in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`, `Created a new stylesheet in ${chalk_1.default.magenta(targetFile2.replace(basePath, ''))}`, `Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
709
- });
700
+ };
710
701
  exports.createSetComponent = createSetComponent;
711
- const createComponent = (name, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
702
+ const createComponent = async (name, basePath = process.cwd()) => {
712
703
  let sourceFolder = getSourceFolder(basePath);
713
704
  let targetFolder = ensureFolderExists(sourceFolder, 'components');
714
705
  let { hyphenName, camelCaseName, underscoreName } = (0, exports.setNameVariables)(name);
@@ -719,7 +710,7 @@ const createComponent = (name, basePath = process.cwd()) => __awaiter(void 0, vo
719
710
  let targetFile2 = path_1.default.join(targetFolder, hyphenName + '.scss');
720
711
  fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'component.scss'), targetFile2);
721
712
  //replace variables in some of the copied files
722
- yield replaceVariablesInFiles(targetFile, targetFile2);
713
+ await replaceVariablesInFiles(targetFile, targetFile2);
723
714
  log(`Created a new component template in ${chalk_1.default.magenta(targetFile.replace(basePath, ''))}`, `Created component stylesheet template in ${chalk_1.default.magenta(targetFile2.replace(basePath, ''))}`);
724
715
  //if this is not a lincd app (but a lincd package instead)
725
716
  if (!sourceFolder.includes('frontend')) {
@@ -727,13 +718,13 @@ const createComponent = (name, basePath = process.cwd()) => __awaiter(void 0, vo
727
718
  let indexPath = addLineToIndex(`import './components/${hyphenName}';`, 'components');
728
719
  log(`Added an import of this file from ${chalk_1.default.magenta(indexPath)}`);
729
720
  }
730
- });
721
+ };
731
722
  exports.createComponent = createComponent;
732
723
  //read the source of all ts/tsx files in the src folder
733
724
  //if there is an import that imports a lincd package with /src/ in it, then warn
734
725
  //if there is an import that imports outside of the src folder, then warn
735
- const checkImports = (sourceFolder = getSourceFolder(), depth = 0, // Used to check if the import is outside of the src folder
736
- invalidImports = new Map()) => __awaiter(void 0, void 0, void 0, function* () {
726
+ const checkImports = async (sourceFolder = getSourceFolder(), depth = 0, // Used to check if the import is outside of the src folder
727
+ invalidImports = new Map()) => {
737
728
  const dir = fs_extra_1.default.readdirSync(sourceFolder);
738
729
  // Start checking each file in the source folder
739
730
  for (const file of dir) {
@@ -743,14 +734,14 @@ invalidImports = new Map()) => __awaiter(void 0, void 0, void 0, function* () {
743
734
  // i.e. the program not having access to check the file metadata
744
735
  if (!filename.match(/\.tsx?$/)) {
745
736
  if ((0, fs_1.statSync)(filename).isDirectory()) {
746
- yield (0, exports.checkImports)(filename, depth + 1, invalidImports);
737
+ await (0, exports.checkImports)(filename, depth + 1, invalidImports);
747
738
  }
748
739
  // Ignore all files that aren't one of the following:
749
740
  // - .ts
750
741
  // - .tsx
751
742
  continue;
752
743
  }
753
- const allImports = yield (0, utils_1.getFileImports)(filename);
744
+ const allImports = await (0, utils_1.getFileImports)(filename);
754
745
  const lincdImports = allImports.filter((i) => i.includes('lincd') || i.includes('..'));
755
746
  lincdImports.forEach((i) => {
756
747
  if (!(0, utils_1.isValidLINCDImport)(i, depth)) {
@@ -776,33 +767,31 @@ invalidImports = new Map()) => __awaiter(void 0, void 0, void 0, function* () {
776
767
  console.info('All imports OK');
777
768
  process.exit(0);
778
769
  }
779
- });
770
+ };
780
771
  exports.checkImports = checkImports;
781
- const depCheckStaged = () => __awaiter(void 0, void 0, void 0, function* () {
772
+ const depCheckStaged = async () => {
782
773
  console.log('Checking dependencies of staged files');
783
- stagedGitFiles(function (err, results) {
784
- return __awaiter(this, void 0, void 0, function* () {
785
- const packages = new Set();
786
- yield Promise.all(results.map((file) => __awaiter(this, void 0, void 0, function* () {
787
- // console.log('STAGED: ', file.filename);
788
- let root = yield (0, find_nearest_package_json_1.findNearestPackageJson)(file.filename);
789
- packages.add(root.path);
790
- })));
791
- [...packages].forEach((packageRoot) => {
792
- const pack = JSON.parse(fs_extra_1.default.readFileSync(packageRoot, 'utf8'));
793
- const srcPath = packageRoot.replace('package.json', '');
794
- console.log('Checking dependencies of ' + chalk_1.default.blue(pack.name) + ':');
795
- return (0, exports.depCheck)(process.cwd() + '/' + srcPath);
796
- // console.log('check dependencies of ' + pack.name);
797
- //
798
- // console.log('ROOT of ' + file.filename + ': ' + root.path);
799
- // console.log('ROOT of ' + file.filename + ': ' + root.data);
800
- });
774
+ stagedGitFiles(async function (err, results) {
775
+ const packages = new Set();
776
+ await Promise.all(results.map(async (file) => {
777
+ // console.log('STAGED: ', file.filename);
778
+ let root = await (0, find_nearest_package_json_1.findNearestPackageJson)(file.filename);
779
+ packages.add(root.path);
780
+ }));
781
+ [...packages].forEach((packageRoot) => {
782
+ const pack = JSON.parse(fs_extra_1.default.readFileSync(packageRoot, 'utf8'));
783
+ const srcPath = packageRoot.replace('package.json', '');
784
+ console.log('Checking dependencies of ' + chalk_1.default.blue(pack.name) + ':');
785
+ return (0, exports.depCheck)(process.cwd() + '/' + srcPath);
786
+ // console.log('check dependencies of ' + pack.name);
787
+ //
788
+ // console.log('ROOT of ' + file.filename + ': ' + root.path);
789
+ // console.log('ROOT of ' + file.filename + ': ' + root.data);
801
790
  });
802
791
  });
803
- });
792
+ };
804
793
  exports.depCheckStaged = depCheckStaged;
805
- const depCheck = (path = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
794
+ const depCheck = async (path = process.cwd()) => {
806
795
  (0, depcheck_1.default)(path, {}, (results) => {
807
796
  if (results.missing) {
808
797
  let lincdPackages = getLocalLincdModules();
@@ -840,9 +829,9 @@ const depCheck = (path = process.cwd()) => __awaiter(void 0, void 0, void 0, fun
840
829
  // console.warn("Unused dependencies: "+results.missing.join(", "));
841
830
  // }
842
831
  });
843
- });
832
+ };
844
833
  exports.depCheck = depCheck;
845
- const ensureEnvironmentLoaded = () => __awaiter(void 0, void 0, void 0, function* () {
834
+ const ensureEnvironmentLoaded = async () => {
846
835
  if (!process.env.NODE_ENV) {
847
836
  //load env-cmd for development environment
848
837
  let { GetEnvVars } = require('env-cmd');
@@ -851,7 +840,7 @@ const ensureEnvironmentLoaded = () => __awaiter(void 0, void 0, void 0, function
851
840
  console.warn('No .env-cmdrc.json found in this folder. Are you running this command from the root of a LINCD app?');
852
841
  process.exit();
853
842
  }
854
- let vars = yield GetEnvVars({
843
+ let vars = await GetEnvVars({
855
844
  envFile: {
856
845
  filePath: envCmdrcPath,
857
846
  },
@@ -859,7 +848,7 @@ const ensureEnvironmentLoaded = () => __awaiter(void 0, void 0, void 0, function
859
848
  let environments = Object.keys(vars);
860
849
  //if _main is present, load it first
861
850
  if (environments.includes('_main')) {
862
- process.env = Object.assign(Object.assign({}, process.env), vars._main);
851
+ process.env = { ...process.env, ...vars._main };
863
852
  }
864
853
  //if --env is passed, load that environment
865
854
  let args = process.argv.splice(2);
@@ -868,7 +857,7 @@ const ensureEnvironmentLoaded = () => __awaiter(void 0, void 0, void 0, function
868
857
  let env = args[envIndex + 1];
869
858
  if (environments.includes(env)) {
870
859
  console.log('Environment: ' + env);
871
- process.env = Object.assign(Object.assign({}, process.env), vars[env]);
860
+ process.env = { ...process.env, ...vars[env] };
872
861
  }
873
862
  else {
874
863
  console.warn('Environment ' +
@@ -879,17 +868,21 @@ const ensureEnvironmentLoaded = () => __awaiter(void 0, void 0, void 0, function
879
868
  }
880
869
  else {
881
870
  //chose development by default
882
- process.env = Object.assign(Object.assign({}, process.env), vars.development);
871
+ process.env = { ...process.env, ...vars.development };
883
872
  console.log('No environment specified, using development');
884
873
  }
885
874
  }
886
- });
887
- const startServer = (initOnly = false) => __awaiter(void 0, void 0, void 0, function* () {
888
- yield ensureEnvironmentLoaded();
875
+ };
876
+ exports.ensureEnvironmentLoaded = ensureEnvironmentLoaded;
877
+ const startServer = async (initOnly = false) => {
878
+ await (0, exports.ensureEnvironmentLoaded)();
889
879
  const LincdServer = require('lincd-server/lib/shapes/LincdServer');
890
880
  let lincdConfig = require(path_1.default.join(process.cwd(), 'lincd.config'));
891
881
  require(path_1.default.join(process.cwd(), 'scripts', 'storage-config'));
892
- let server = new LincdServer.LincdServer(Object.assign({ loadAppComponent: () => require(path_1.default.join(process.cwd(), 'src', 'App')).default }, lincdConfig));
882
+ let server = new LincdServer.LincdServer({
883
+ loadAppComponent: () => require(path_1.default.join(process.cwd(), 'src', 'App')).default,
884
+ ...lincdConfig,
885
+ });
893
886
  let args = process.argv.splice(2);
894
887
  //if --initOnly is passed, only initialize the server and don't start it
895
888
  if (args.includes('--initOnly') || initOnly) {
@@ -898,9 +891,53 @@ const startServer = (initOnly = false) => __awaiter(void 0, void 0, void 0, func
898
891
  else {
899
892
  return server.start();
900
893
  }
901
- });
894
+ };
902
895
  exports.startServer = startServer;
903
- const createPackage = (name, uriBase, basePath = process.cwd()) => __awaiter(void 0, void 0, void 0, function* () {
896
+ const buildApp = async () => {
897
+ await (0, exports.ensureEnvironmentLoaded)();
898
+ const webpackAppConfig = require('./config-webpack-app').webpackAppConfig;
899
+ console.log(chalk_1.default.magenta(`Building ${process.env.NODE_ENV} app bundles`));
900
+ return new Promise((resolve, reject) => {
901
+ webpack(webpackAppConfig, async (err, stats) => {
902
+ if (err) {
903
+ console.error(err.stack || err);
904
+ if (err.details) {
905
+ console.error(err.details);
906
+ }
907
+ process.exit(1);
908
+ }
909
+ const info = stats.toJson();
910
+ if (stats.hasErrors()) {
911
+ console.log('Finished running webpack with errors.');
912
+ info.errors.forEach((e) => console.error(e));
913
+ // process.exit(1);
914
+ reject();
915
+ }
916
+ else {
917
+ console.log(stats.toString({
918
+ chunks: false,
919
+ assets: true,
920
+ entryPoints: false,
921
+ modules: false,
922
+ moduleAssets: false,
923
+ moduleChunks: false,
924
+ colors: true,
925
+ }));
926
+ console.log('App build process finished');
927
+ resolve(true);
928
+ // console.log(
929
+ // chalk.green('\t'+Object.keys(stats.compilation.assets).join('\n\t')),
930
+ // );
931
+ //build metadata (JSON-LD files containing metadata about the lincd components, shapes & ontologies in this app or its packages)
932
+ // let updatedPaths = await buildMetadata();
933
+ // console.log(chalk.green("Updated metadata:\n")+" - "+updatedPaths.map(p => chalk.magenta(p.replace(process.cwd(),''))).join("\n - "));
934
+ }
935
+ // process.exit();
936
+ });
937
+ });
938
+ };
939
+ exports.buildApp = buildApp;
940
+ const createPackage = async (name, uriBase, basePath = process.cwd()) => {
904
941
  //if ran with npx, basePath will be the root directory of the repository, even if we're executing from a sub folder (the root directory is where node_modules lives and package.json with workspaces)
905
942
  //so we manually find a packages folder, if it exists we go into that.
906
943
  if (fs_extra_1.default.existsSync(path_1.default.join(basePath, 'packages'))) {
@@ -930,7 +967,7 @@ const createPackage = (name, uriBase, basePath = process.cwd()) => __awaiter(voi
930
967
  log("Creating new LINCD package '" + name + "'");
931
968
  fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'package'), targetFolder);
932
969
  //replace variables in some of the copied files
933
- yield Promise.all([
970
+ await Promise.all([
934
971
  'src/index.ts',
935
972
  'package.json',
936
973
  'Gruntfile.js',
@@ -956,18 +993,18 @@ const createPackage = (name, uriBase, basePath = process.cwd()) => __awaiter(voi
956
993
  console.log('rename ', path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
957
994
  fs_extra_1.default.renameSync(path_1.default.join(targetFolder, f), path_1.default.join(targetFolder, ...newParts, newName));
958
995
  });
959
- let version = (yield (0, utils_1.execPromise)('yarn --version').catch((err) => {
996
+ let version = (await (0, utils_1.execPromise)('yarn --version').catch((err) => {
960
997
  console.log('yarn probably not working');
961
998
  return '';
962
999
  }));
963
1000
  let installCommand = version.toString().match(/[0-9]+/)
964
1001
  ? 'yarn install'
965
1002
  : 'npm install';
966
- yield (0, utils_1.execp)(`cd ${targetFolder} && ${installCommand} && npm exec lincd build`, true).catch((err) => {
1003
+ await (0, utils_1.execp)(`cd ${targetFolder} && ${installCommand} && npm exec lincd build`, true).catch((err) => {
967
1004
  console.warn('Could not install dependencies');
968
1005
  });
969
1006
  log(`Prepared a new LINCD package in ${chalk_1.default.magenta(targetFolder)}`, `Run ${chalk_1.default.blueBright('yarn build')} from this directory to build once`, `Or ${chalk_1.default.blueBright('yarn dev')} to continuously rebuild on file changes`);
970
- });
1007
+ };
971
1008
  exports.createPackage = createPackage;
972
1009
  var getNextVersion = function (version) {
973
1010
  let parts = version.split('.');
@@ -1148,7 +1185,7 @@ var publishUpdated = function (test = false) {
1148
1185
  }
1149
1186
  console.log('testing npm');
1150
1187
  return (0, utils_1.execPromise)('npm info ' + pckg.packageName + ' --json')
1151
- .then((output) => __awaiter(this, void 0, void 0, function* () {
1188
+ .then(async (output) => {
1152
1189
  console.log('testing npm done');
1153
1190
  var info;
1154
1191
  try {
@@ -1176,7 +1213,7 @@ var publishUpdated = function (test = false) {
1176
1213
  // }
1177
1214
  let lastPublishDate = new Date(lastPublish);
1178
1215
  // let {lastModifiedTime, lastModifiedName, lastModified} = getLastModifiedSourceTime(pkg.path);
1179
- let lastCommitInfo = yield (0, utils_1.getLastCommitTime)(pckg.path);
1216
+ let lastCommitInfo = await (0, utils_1.getLastCommitTime)(pckg.path);
1180
1217
  if (!lastCommitInfo) {
1181
1218
  shouldPublish = false;
1182
1219
  (0, utils_1.debugInfo)('Could not determine last git commit');
@@ -1229,7 +1266,7 @@ var publishUpdated = function (test = false) {
1229
1266
  return (0, exports.publishPackage)(pckg, test, info, version);
1230
1267
  }
1231
1268
  return (chalk_1.default.blue(pckg.packageName) + ' latest version is up to date');
1232
- }))
1269
+ })
1233
1270
  .catch(({ error, stdout, stderr }) => {
1234
1271
  if (error) {
1235
1272
  console.log(error.message);
@@ -1266,153 +1303,147 @@ var publishUpdated = function (test = false) {
1266
1303
  });
1267
1304
  };
1268
1305
  exports.publishUpdated = publishUpdated;
1269
- function getEnvJsonPath(relativeToPath = process.cwd()) {
1270
- return __awaiter(this, void 0, void 0, function* () {
1271
- let path = '';
1272
- if (!relativeToPath.endsWith('/')) {
1273
- relativeToPath += '/';
1274
- }
1275
- // let path = './';
1276
- for (let i = 0; i <= 10; i++) {
1277
- let envFile = yield (0, get_env_vars_1.getEnvFile)({
1278
- filePath: relativeToPath + path + '.env.json',
1279
- }).catch((err) => {
1280
- return null;
1281
- });
1282
- if (envFile) {
1283
- //note: we're getting the actual contents here, so we could also use that more directly?
1284
- return path + '.env.json';
1285
- }
1286
- path += '../';
1306
+ async function getEnvJsonPath(relativeToPath = process.cwd()) {
1307
+ let path = '';
1308
+ if (!relativeToPath.endsWith('/')) {
1309
+ relativeToPath += '/';
1310
+ }
1311
+ // let path = './';
1312
+ for (let i = 0; i <= 10; i++) {
1313
+ let envFile = await (0, get_env_vars_1.getEnvFile)({
1314
+ filePath: relativeToPath + path + '.env.json',
1315
+ }).catch((err) => {
1316
+ return null;
1317
+ });
1318
+ if (envFile) {
1319
+ //note: we're getting the actual contents here, so we could also use that more directly?
1320
+ return path + '.env.json';
1287
1321
  }
1288
- });
1322
+ path += '../';
1323
+ }
1289
1324
  }
1290
- var publishPackage = function (pkg, test, info, publishVersion) {
1291
- return __awaiter(this, void 0, void 0, function* () {
1292
- if (!pkg) {
1293
- let localPackageJson = (0, utils_1.getPackageJSON)();
1294
- pkg = {
1295
- path: process.cwd(),
1296
- packageName: localPackageJson.name,
1297
- };
1298
- }
1299
- if (!publishVersion) {
1300
- publishVersion = info ? getNextVersion(info.version) : 'patch';
1301
- }
1302
- if (test) {
1303
- (0, utils_1.debugInfo)('should publish ' + pkg.packageName + ' ' + publishVersion);
1304
- //when testing what needs to be published
1305
- return chalk_1.default.blue(pkg.packageName + ' should publish');
1325
+ var publishPackage = async function (pkg, test, info, publishVersion) {
1326
+ if (!pkg) {
1327
+ let localPackageJson = (0, utils_1.getPackageJSON)();
1328
+ pkg = {
1329
+ path: process.cwd(),
1330
+ packageName: localPackageJson.name,
1331
+ };
1332
+ }
1333
+ if (!publishVersion) {
1334
+ publishVersion = info ? getNextVersion(info.version) : 'patch';
1335
+ }
1336
+ if (test) {
1337
+ (0, utils_1.debugInfo)('should publish ' + pkg.packageName + ' ' + publishVersion);
1338
+ //when testing what needs to be published
1339
+ return chalk_1.default.blue(pkg.packageName + ' should publish');
1340
+ }
1341
+ console.log(chalk_1.default.blue('publishing ' + pkg.packageName + ' ' + publishVersion));
1342
+ //looking for an .env.json file in our workspace, which may store our NPM AUTH key
1343
+ let envJsonPath = await getEnvJsonPath(pkg.path);
1344
+ return (0, utils_1.execPromise)(`cd ${pkg.path} && ${envJsonPath ? `env-cmd -f ${envJsonPath} --use-shell "` : ''}yarn version ${publishVersion} && yarn npm publish${envJsonPath ? `"` : ''}`, true, false, {}, true)
1345
+ .then((res) => {
1346
+ if (res.indexOf('Aborted due to warnings') !== -1 ||
1347
+ res.indexOf('Could not publish') !== -1 ||
1348
+ res.indexOf("Couldn't publish") !== -1) {
1349
+ console.log(res);
1350
+ return chalk_1.default.red(pkg.packageName + ' failed\n');
1306
1351
  }
1307
- console.log(chalk_1.default.blue('publishing ' + pkg.packageName + ' ' + publishVersion));
1308
- //looking for an .env.json file in our workspace, which may store our NPM AUTH key
1309
- let envJsonPath = yield getEnvJsonPath(pkg.path);
1310
- return (0, utils_1.execPromise)(`cd ${pkg.path} && ${envJsonPath ? `env-cmd -f ${envJsonPath} --use-shell "` : ''}yarn version ${publishVersion} && yarn npm publish${envJsonPath ? `"` : ''}`, true, false, {}, true)
1311
- .then((res) => {
1312
- if (res.indexOf('Aborted due to warnings') !== -1 ||
1313
- res.indexOf('Could not publish') !== -1 ||
1314
- res.indexOf("Couldn't publish") !== -1) {
1315
- console.log(res);
1316
- return chalk_1.default.red(pkg.packageName + ' failed\n');
1317
- }
1318
- console.log('Successfully published ' +
1319
- chalk_1.default.green(pkg.path) +
1320
- ' ' +
1321
- chalk_1.default.magenta(publishVersion));
1322
- return (chalk_1.default.green(pkg.packageName) +
1323
- ' published ' +
1324
- chalk_1.default.magenta(publishVersion));
1325
- })
1326
- .catch(({ error, stdout, stderr }) => {
1327
- console.log(chalk_1.default.red('Failed to publish: ' + error.message));
1328
- return chalk_1.default.red(pkg.packageName + ' failed to publish');
1329
- });
1352
+ console.log('Successfully published ' +
1353
+ chalk_1.default.green(pkg.path) +
1354
+ ' ' +
1355
+ chalk_1.default.magenta(publishVersion));
1356
+ return (chalk_1.default.green(pkg.packageName) +
1357
+ ' published ' +
1358
+ chalk_1.default.magenta(publishVersion));
1359
+ })
1360
+ .catch(({ error, stdout, stderr }) => {
1361
+ console.log(chalk_1.default.red('Failed to publish: ' + error.message));
1362
+ return chalk_1.default.red(pkg.packageName + ' failed to publish');
1330
1363
  });
1331
1364
  };
1332
1365
  exports.publishPackage = publishPackage;
1333
- var buildUpdated = function (back, target, target2, useGitForLastModified = false, test = false) {
1334
- return __awaiter(this, void 0, void 0, function* () {
1335
- // back = back || 1;
1336
- // return execPromise(`git log -${back} --format=%ci`).then((result) => {
1337
- // let now = new Date();
1338
- let previousResult = '';
1339
- log(test
1340
- ? 'Checking which packages need to be rebuild'
1341
- : 'Building updated packages');
1342
- // let packages = getLocalLincdModules();
1343
- let packages = getLocalLincdPackageMap();
1344
- // console.log(packages);
1345
- let jsonldPkgUpdated = yield (0, utils_1.needsRebuilding)(packages.get('lincd-jsonld'), useGitForLastModified);
1346
- // let cliPkgUpdated = await needsRebuilding(packages.get('lincd-cli'), useGitForLastModified);
1347
- //if either cli or jsonldPkg needs to be rebuilt
1348
- // if (jsonldPkgUpdated || cliPkgUpdated) {
1349
- if (jsonldPkgUpdated) {
1350
- yield (0, utils_1.execPromise)('yarn exec tsc && echo "compiled lincd-jsonld"', false, false, {
1351
- cwd: packages.get('lincd-jsonld').path,
1352
- }, true);
1353
- // await execPromise('yarn build-core', false, false, {}, true);
1354
- }
1355
- let rebuildAllModules = false;
1356
- // if (cliPkgUpdated) {
1357
- // rebuildAllModules = true;
1358
- // log(chalk.magenta('Rebuilding all packages because the build tools (lincd-cli) got updated'));
1359
- // }
1360
- let packagesLeft = packages.size;
1361
- runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
1362
- (0, utils_1.debugInfo)('Now checking: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
1363
- (0, utils_1.debugInfo)(packagesLeft + ' packages left.');
1364
- packagesLeft = packagesLeft - packageGroup.length;
1365
- return (pkg) => __awaiter(this, void 0, void 0, function* () {
1366
- // debugInfo('# Checking package ' + pkg.packageName);
1367
- let needRebuild = yield (0, utils_1.needsRebuilding)(pkg, useGitForLastModified);
1368
- if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated) {
1369
- needRebuild = true;
1370
- }
1371
- if (needRebuild || rebuildAllModules) {
1372
- //TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
1373
- // log(packageName+' modified since last commit on '+now.toString());
1374
- if (test) {
1375
- (0, utils_1.debugInfo)('Need to build ' + pkg.packageName);
1376
- return chalk_1.default.blue(pkg.packageName + ' should be build');
1377
- }
1378
- log('Building ' + pkg.packageName);
1379
- return (0, utils_1.execPromise)('cd ' +
1380
- pkg.path +
1381
- ' && yarn build' +
1382
- (target ? ' ' + target : '') +
1383
- (target2 ? ' ' + target2 : ''))
1384
- .then((res) => {
1385
- (0, utils_1.debugInfo)(chalk_1.default.green(pkg.packageName + ' successfully built'));
1386
- return chalk_1.default.green(pkg.packageName + ' built');
1387
- })
1388
- .catch(({ error, stdout, stderr }) => {
1389
- warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
1390
- console.log(stdout);
1391
- process.exit(1);
1392
- // let dependentModules = getDependentPackages(dependencies, pkg);
1393
- // if (dependentModules.length > 0) {
1394
- // // printBuildResults(failedModules, done);
1395
- // warn(chalk.red(pkg.packageName + ' build failed'));
1396
- // warn(
1397
- // 'Stopping build-updated process because ' +
1398
- // dependentModules.length +
1399
- // ' other packages depend on this package.\n',
1400
- // ); //"+dependentModules.map(d => d.packageName).join(", ")));
1401
- // }
1402
- });
1403
- }
1404
- });
1405
- }, (results) => {
1406
- if (results.length) {
1407
- log('Summary:');
1408
- log(results.join('\n'));
1366
+ var buildUpdated = async function (back, target, target2, useGitForLastModified = false, test = false) {
1367
+ // back = back || 1;
1368
+ // return execPromise(`git log -${back} --format=%ci`).then((result) => {
1369
+ // let now = new Date();
1370
+ let previousResult = '';
1371
+ log(test
1372
+ ? 'Checking which packages need to be rebuild'
1373
+ : 'Building updated packages');
1374
+ // let packages = getLocalLincdModules();
1375
+ let packages = getLocalLincdPackageMap();
1376
+ // console.log(packages);
1377
+ let jsonldPkgUpdated = await (0, utils_1.needsRebuilding)(packages.get('lincd-jsonld'), useGitForLastModified);
1378
+ // let cliPkgUpdated = await needsRebuilding(packages.get('lincd-cli'), useGitForLastModified);
1379
+ //if either cli or jsonldPkg needs to be rebuilt
1380
+ // if (jsonldPkgUpdated || cliPkgUpdated) {
1381
+ if (jsonldPkgUpdated) {
1382
+ await (0, utils_1.execPromise)('yarn exec tsc && echo "compiled lincd-jsonld"', false, false, {
1383
+ cwd: packages.get('lincd-jsonld').path,
1384
+ }, true);
1385
+ // await execPromise('yarn build-core', false, false, {}, true);
1386
+ }
1387
+ let rebuildAllModules = false;
1388
+ // if (cliPkgUpdated) {
1389
+ // rebuildAllModules = true;
1390
+ // log(chalk.magenta('Rebuilding all packages because the build tools (lincd-cli) got updated'));
1391
+ // }
1392
+ let packagesLeft = packages.size;
1393
+ runOnPackagesGroupedByDependencies(packages, (packageGroup, dependencies) => {
1394
+ (0, utils_1.debugInfo)('Now checking: ' + chalk_1.default.blue(packageGroup.map((i) => i.packageName)));
1395
+ (0, utils_1.debugInfo)(packagesLeft + ' packages left.');
1396
+ packagesLeft = packagesLeft - packageGroup.length;
1397
+ return async (pkg) => {
1398
+ // debugInfo('# Checking package ' + pkg.packageName);
1399
+ let needRebuild = await (0, utils_1.needsRebuilding)(pkg, useGitForLastModified);
1400
+ if (pkg.packageName === 'lincd-jsonld' && jsonldPkgUpdated) {
1401
+ needRebuild = true;
1409
1402
  }
1410
- else {
1411
- log(chalk_1.default.green('Nothing to rebuild'));
1403
+ if (needRebuild || rebuildAllModules) {
1404
+ //TODO: when building a pkg, also rebuild all packages that depend on this package.. and iteratively build packages that depend on those packages..
1405
+ // log(packageName+' modified since last commit on '+now.toString());
1406
+ if (test) {
1407
+ (0, utils_1.debugInfo)('Need to build ' + pkg.packageName);
1408
+ return chalk_1.default.blue(pkg.packageName + ' should be build');
1409
+ }
1410
+ log('Building ' + pkg.packageName);
1411
+ return (0, utils_1.execPromise)('cd ' +
1412
+ pkg.path +
1413
+ ' && yarn build' +
1414
+ (target ? ' ' + target : '') +
1415
+ (target2 ? ' ' + target2 : ''))
1416
+ .then((res) => {
1417
+ (0, utils_1.debugInfo)(chalk_1.default.green(pkg.packageName + ' successfully built'));
1418
+ return chalk_1.default.green(pkg.packageName + ' built');
1419
+ })
1420
+ .catch(({ error, stdout, stderr }) => {
1421
+ warn(chalk_1.default.red('Failed to build ' + pkg.packageName));
1422
+ console.log(stdout);
1423
+ process.exit(1);
1424
+ // let dependentModules = getDependentPackages(dependencies, pkg);
1425
+ // if (dependentModules.length > 0) {
1426
+ // // printBuildResults(failedModules, done);
1427
+ // warn(chalk.red(pkg.packageName + ' build failed'));
1428
+ // warn(
1429
+ // 'Stopping build-updated process because ' +
1430
+ // dependentModules.length +
1431
+ // ' other packages depend on this package.\n',
1432
+ // ); //"+dependentModules.map(d => d.packageName).join(", ")));
1433
+ // }
1434
+ });
1412
1435
  }
1413
- });
1414
- return;
1436
+ };
1437
+ }, (results) => {
1438
+ if (results.length) {
1439
+ log('Summary:');
1440
+ log(results.join('\n'));
1441
+ }
1442
+ else {
1443
+ log(chalk_1.default.green('Nothing to rebuild'));
1444
+ }
1415
1445
  });
1446
+ return;
1416
1447
  };
1417
1448
  exports.buildUpdated = buildUpdated;
1418
1449
  const printBuildResults = function (failed, done) {
@@ -1476,61 +1507,59 @@ var addLinesToFile = function (filePath, entries) {
1476
1507
  fs_extra_1.default.writeFileSync(filePath, fileContents);
1477
1508
  };
1478
1509
  exports.addLinesToFile = addLinesToFile;
1479
- var addCapacitor = function (basePath = process.cwd()) {
1480
- return __awaiter(this, void 0, void 0, function* () {
1481
- let targetFolder = ensureFolderExists(basePath);
1482
- log('Adding capacitor');
1483
- fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'app-static'), targetFolder);
1484
- fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'capacitor', 'scripts'), path_1.default.join(targetFolder, 'scripts'));
1485
- //update .env-cmdrc.json file
1486
- let envCmdPath = path_1.default.resolve(basePath, '.env-cmdrc.json');
1487
- let envCmd = JSON.parse(fs_extra_1.default.readFileSync(envCmdPath, { encoding: 'utf8' }));
1488
- envCmd['app-main'] = {
1489
- APP_ENV: true,
1490
- OUTPUT_PATH: './web/assets',
1491
- ASSET_PATH: './assets/',
1492
- ENTRY_PATH: './src/index-static.tsx',
1493
- };
1494
- envCmd['app-local-android'] = {
1495
- NODE_ENV: 'app',
1496
- SITE_ROOT: 'http://10.0.2.2:4000',
1497
- };
1498
- envCmd['app-local-ios'] = {
1499
- NODE_ENV: 'app',
1500
- SITE_ROOT: 'http://localhost:4000',
1501
- };
1502
- fs_extra_1.default.writeFile(envCmdPath, JSON.stringify(envCmd, null, 2));
1503
- log('Edited .env-cmdrc.json');
1504
- gitIgnore('android/app/build', 'android/**/capacitor.build.gradle', 'ios/App/App/public');
1505
- //update package.json scripts
1506
- let pack = (0, utils_1.getPackageJSON)(basePath);
1507
- pack.scripts['build-staging'] =
1508
- 'env-cmd -e _main, staging node scripts/build.js';
1509
- pack.scripts['fix-app'] = 'node scripts/fix-namespace.js';
1510
- pack.scripts['app'] =
1511
- 'env-cmd -e _main,production,app-main node scripts/build.js && npx cap sync && yarn run fix-app';
1512
- pack.scripts['app-local-ios'] =
1513
- 'env-cmd -e _main,development,app-main,app-local-ios node scripts/build.js && npx cap sync && yarn run fix-app';
1514
- pack.scripts['app-local-android'] =
1515
- 'env-cmd -e _main,development,app-main,app-local-android node scripts/build.js && npx cap sync && yarn run fix-app';
1516
- pack.scripts['cap:android'] = 'yarn cap open android';
1517
- pack.scripts['cap:ios'] = 'yarn cap open ios';
1518
- pack.scripts['cap:sync'] = 'yarn cap sync';
1519
- fs_extra_1.default.writeFile(path_1.default.resolve(basePath, 'package.json'), JSON.stringify(pack, null, 2));
1520
- log('Added new run script to package.json');
1521
- yield (0, utils_1.execPromise)(`yarn add -D @capacitor/cli`, true, false, null, true);
1522
- yield (0, utils_1.execPromise)(`yarn add @capacitor/android @capacitor/core @capacitor/app @capacitor/ios`, false, false, null, true);
1523
- // TODO: Do we need to add `npx cap init`? If yes, we should not copy capacitor config.ts yet
1524
- // await execPromise(`npx cap init`, true, false, null, true);
1525
- // got error:
1526
- // [error] Non-interactive shell detected.
1527
- // Run the command with --help to see a list of arguments that must be provided.
1528
- // [error] Non-interactive shell detected.
1529
- // Run the command with --help to see a list of arguments that must be provided.
1530
- log(`Done! Now update your Capacitor configuration by providing an app name, app ID, and web directory at ${chalk_1.default.blue('capacitor.config.ts')}`);
1531
- log(`And then run ${chalk_1.default.magenta('yarn cap add android')} and/or ${chalk_1.default.magenta('yarn cap add ios')}')`);
1532
- log(`Last, run ${chalk_1.default.magenta('yarn app')} or ${chalk_1.default.magenta('yarn app-local-ios')} or ${chalk_1.default.magenta('yarn app-local-android')}`);
1533
- });
1510
+ var addCapacitor = async function (basePath = process.cwd()) {
1511
+ let targetFolder = ensureFolderExists(basePath);
1512
+ log('Adding capacitor');
1513
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'app-static'), targetFolder);
1514
+ fs_extra_1.default.copySync(path_1.default.join(__dirname, '..', 'defaults', 'capacitor', 'scripts'), path_1.default.join(targetFolder, 'scripts'));
1515
+ //update .env-cmdrc.json file
1516
+ let envCmdPath = path_1.default.resolve(basePath, '.env-cmdrc.json');
1517
+ let envCmd = JSON.parse(fs_extra_1.default.readFileSync(envCmdPath, { encoding: 'utf8' }));
1518
+ envCmd['app-main'] = {
1519
+ APP_ENV: true,
1520
+ OUTPUT_PATH: './web/assets',
1521
+ ASSET_PATH: './assets/',
1522
+ ENTRY_PATH: './src/index-static.tsx',
1523
+ };
1524
+ envCmd['app-local-android'] = {
1525
+ NODE_ENV: 'app',
1526
+ SITE_ROOT: 'http://10.0.2.2:4000',
1527
+ };
1528
+ envCmd['app-local-ios'] = {
1529
+ NODE_ENV: 'app',
1530
+ SITE_ROOT: 'http://localhost:4000',
1531
+ };
1532
+ fs_extra_1.default.writeFile(envCmdPath, JSON.stringify(envCmd, null, 2));
1533
+ log('Edited .env-cmdrc.json');
1534
+ gitIgnore('android/app/build', 'android/**/capacitor.build.gradle', 'ios/App/App/public');
1535
+ //update package.json scripts
1536
+ let pack = (0, utils_1.getPackageJSON)(basePath);
1537
+ pack.scripts['build-staging'] =
1538
+ 'env-cmd -e _main, staging node scripts/build.js';
1539
+ pack.scripts['fix-app'] = 'node scripts/fix-namespace.js';
1540
+ pack.scripts['app'] =
1541
+ 'env-cmd -e _main,production,app-main node scripts/build.js && npx cap sync && yarn run fix-app';
1542
+ pack.scripts['app-local-ios'] =
1543
+ 'env-cmd -e _main,development,app-main,app-local-ios node scripts/build.js && npx cap sync && yarn run fix-app';
1544
+ pack.scripts['app-local-android'] =
1545
+ 'env-cmd -e _main,development,app-main,app-local-android node scripts/build.js && npx cap sync && yarn run fix-app';
1546
+ pack.scripts['cap:android'] = 'yarn cap open android';
1547
+ pack.scripts['cap:ios'] = 'yarn cap open ios';
1548
+ pack.scripts['cap:sync'] = 'yarn cap sync';
1549
+ fs_extra_1.default.writeFile(path_1.default.resolve(basePath, 'package.json'), JSON.stringify(pack, null, 2));
1550
+ log('Added new run script to package.json');
1551
+ await (0, utils_1.execPromise)(`yarn add -D @capacitor/cli`, true, false, null, true);
1552
+ await (0, utils_1.execPromise)(`yarn add @capacitor/android @capacitor/core @capacitor/app @capacitor/ios`, false, false, null, true);
1553
+ // TODO: Do we need to add `npx cap init`? If yes, we should not copy capacitor config.ts yet
1554
+ // await execPromise(`npx cap init`, true, false, null, true);
1555
+ // got error:
1556
+ // [error] Non-interactive shell detected.
1557
+ // Run the command with --help to see a list of arguments that must be provided.
1558
+ // [error] Non-interactive shell detected.
1559
+ // Run the command with --help to see a list of arguments that must be provided.
1560
+ log(`Done! Now update your Capacitor configuration by providing an app name, app ID, and web directory at ${chalk_1.default.blue('capacitor.config.ts')}`);
1561
+ log(`And then run ${chalk_1.default.magenta('yarn cap add android')} and/or ${chalk_1.default.magenta('yarn cap add ios')}')`);
1562
+ log(`Last, run ${chalk_1.default.magenta('yarn app')} or ${chalk_1.default.magenta('yarn app-local-ios')} or ${chalk_1.default.magenta('yarn app-local-android')}`);
1534
1563
  };
1535
1564
  exports.addCapacitor = addCapacitor;
1536
1565
  var executeCommandForPackage = function (packageName, command) {
@@ -1553,3 +1582,4 @@ var executeCommandForPackage = function (packageName, command) {
1553
1582
  }
1554
1583
  };
1555
1584
  exports.executeCommandForPackage = executeCommandForPackage;
1585
+ //# sourceMappingURL=cli-methods.js.map