chore(cli): Cleanup cli package for v4.

This commit is contained in:
Sam Tolmay 2021-11-25 12:42:48 +02:00
parent 67e8f8f1d8
commit ddfcdc5aa8
No known key found for this signature in database
GPG Key ID: D004126FCD1A6DF0
141 changed files with 156 additions and 3151 deletions

1410
.pnp.cjs generated

File diff suppressed because it is too large Load Diff

2
.swcrc
View File

@ -1,5 +1,5 @@
{
"exclude": [".*.test.js$", ".*/tests/.*"],
"exclude": [".*.test.js$", ".*/tests/.*", ".*/__mocks__/.*"],
"jsc": {
"parser": {
"syntax": "ecmascript",

View File

@ -1,13 +0,0 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "12"
}
}
],
"@babel/preset-react"
]
}

View File

@ -3,13 +3,7 @@ module.exports = {
collectCoverage: true,
collectCoverageFrom: ['src/**/*.js'],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: [
'<rootDir>/dist/',
'<rootDir>/src/test',
'<rootDir>/src/index.js',
'<rootDir>/src/index.js',
'<rootDir>/src/commands/dev/shell/*',
],
coveragePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/src/test', '<rootDir>/src/index.js'],
coverageReporters: [['lcov', { projectRoot: '../..' }], 'text', 'clover'],
errorOnDeprecated: true,
testEnvironment: 'node',

View File

@ -25,19 +25,19 @@
"type": "git",
"url": "https://github.com/lowdefy/lowdefy.git"
},
"bin": "dist/index.js",
"type": "module",
"bin": "./dist/index.js",
"files": [
"dist/*"
],
"main": "dist/index.js",
"exports": "./dist/index.js",
"scripts": {
"build": "yarn webpack",
"build": "yarn swc",
"clean": "rm -rf dist && rm -rf .lowdefy",
"cli": "yarn node ./dist/index.js",
"cli:build": "yarn build && yarn node ./dist/index.js",
"start": "yarn node ./dist/index.js",
"prepare": "yarn build",
"test": "FORCE_COLOR=3 jest --coverage",
"webpack": "webpack --config webpack.config.js"
"swc": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
"test": "FORCE_COLOR=3 jest --coverage"
},
"dependencies": {
"@lowdefy/helpers": "4.0.0-alpha.0",
@ -49,7 +49,6 @@
"decompress": "4.2.1",
"decompress-targz": "4.1.1",
"dotenv": "10.0.0",
"fs-extra": "10.0.0",
"js-yaml": "4.1.0",
"opener": "1.5.2",
"ora": "5.4.0",
@ -57,23 +56,10 @@
"uuid": "8.3.2"
},
"devDependencies": {
"@babel/cli": "7.15.7",
"@babel/core": "7.15.8",
"@babel/preset-env": "7.15.8",
"@babel/preset-react": "7.14.5",
"@lowdefy/block-utils": "4.0.0-alpha.0",
"babel-jest": "27.3.1",
"babel-loader": "8.2.3",
"clean-webpack-plugin": "4.0.0",
"copy-webpack-plugin": "9.0.1",
"css-loader": "6.4.0",
"html-webpack-plugin": "5.4.0",
"jest": "27.3.1",
"react": "18.0.0-alpha-327d5c484-20211106",
"react-dom": "18.0.0-alpha-327d5c484-20211106",
"style-loader": "3.3.1",
"webpack": "5.59.1",
"webpack-cli": "4.9.1"
"@swc/cli": "0.1.51",
"@swc/core": "1.2.107",
"@swc/jest": "0.2.5",
"jest": "27.3.1"
},
"publishConfig": {
"access": "public"

View File

@ -1,147 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import path from 'path';
import { spawnSync } from 'child_process';
import fse from 'fs-extra';
import { readFile, writeFile } from '@lowdefy/node-utils';
import checkChildProcessError from '../../utils/checkChildProcessError';
import getFederatedModule from '../../utils/getFederatedModule';
import fetchNpmTarball from '../../utils/fetchNpmTarball';
async function fetchNetlifyServer({ context }) {
context.print.log('Fetching Lowdefy Netlify server.');
await fetchNpmTarball({
packageName: '@lowdefy/server-netlify',
version: context.lowdefyVersion,
directory: context.netlifyDir,
});
context.print.log('Fetched Lowdefy Netlify server.');
}
async function npmInstall({ context }) {
await fse.copy(
path.resolve(context.netlifyDir, 'package/package.json'),
path.resolve('./package.json')
);
await fse.remove(path.resolve('./package-lock.json'));
await fse.remove(path.resolve('./package-lock.json'));
await fse.emptyDir(path.resolve('./node_modules'));
context.print.log('npm install production.');
let processOutput = spawnSync('npm', ['install', '--production', '--legacy-peer-deps']);
checkChildProcessError({
context,
processOutput: processOutput,
message: 'Failed to npm install Netlify server.',
});
context.print.log('npm install successful.');
context.print.log(processOutput.stdout.toString('utf8'));
}
async function fetchBuildScript({ context }) {
context.print.log('Fetching Lowdefy build script.');
const { default: buildScript } = await getFederatedModule({
module: 'build',
packageName: '@lowdefy/build',
version: context.lowdefyVersion,
context,
});
context.print.log('Fetched Lowdefy build script.');
return buildScript;
}
async function build({ context, buildScript }) {
context.print.log('Starting Lowdefy build.');
const buildDirectory = path.resolve(context.netlifyDir, './package/dist/functions/graphql/build');
await buildScript({
blocksServerUrl: context.options.blocksServerUrl,
buildDirectory,
cacheDirectory: context.cacheDirectory,
configDirectory: context.baseDirectory,
logger: context.print,
refResolver: context.options.refResolver,
});
context.print.log(`Build artifacts saved at ${buildDirectory}.`);
}
async function buildIndexHtml({ context }) {
context.print.log('Starting Lowdefy index.html build.');
let appConfig = await readFile(path.resolve('./.lowdefy/functions/graphql/build/app.json'));
appConfig = JSON.parse(appConfig);
const indexHtmlPath = path.resolve('./.lowdefy/publish/index.html');
let indexHtml = await readFile(indexHtmlPath);
indexHtml = indexHtml.replace('<!-- __LOWDEFY_APP_HEAD_HTML__ -->', appConfig.html.appendHead);
indexHtml = indexHtml.replace('<!-- __LOWDEFY_APP_BODY_HTML__ -->', appConfig.html.appendBody);
await writeFile({
filePath: indexHtmlPath,
content: indexHtml,
});
context.print.log('Lowdefy index.html build complete.');
}
async function moveBuildArtifacts({ context }) {
await fse.copy(
path.resolve(context.netlifyDir, 'package/dist/shell'),
path.resolve('./.lowdefy/publish')
);
context.print.log(`Netlify publish artifacts moved to "./lowdefy/publish".`);
}
async function moveFunctions({ context }) {
await fse.copy(
path.resolve(context.netlifyDir, 'package/dist/functions'),
path.resolve('./.lowdefy/functions')
);
context.print.log(`Netlify functions artifacts moved to "./lowdefy/functions".`);
}
async function movePublicAssets({ context }) {
context.print.log(`Moving public assets.`);
await fse.ensureDir(path.resolve('./public'));
await fse.copy(path.resolve('./public'), path.resolve('./.lowdefy/publish/public'));
context.print.log(`Public assets moved to "./lowdefy/publish/public".`);
}
async function buildNetlify({ context }) {
context.netlifyDir = path.resolve(context.baseDirectory, './.lowdefy/netlify');
context.print.info('Starting build.');
const buildScript = await fetchBuildScript({ context });
await build({ context, buildScript });
context.print.info('Installing Lowdefy server.');
await fetchNetlifyServer({ context });
await npmInstall({ context });
context.print.log(`Moving artifacts.`);
await moveBuildArtifacts({ context });
await moveFunctions({ context });
await movePublicAssets({ context });
context.print.log(`Build artifacts.`);
await buildIndexHtml({ context });
await context.sendTelemetry({
data: {
netlify: process.env.NETLIFY === 'true',
},
});
context.print.succeed(`Netlify build completed successfully.`);
}
export default buildNetlify;

View File

@ -1,45 +0,0 @@
/*
Copyright 2020-2021 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import path from 'path';
import fse from 'fs-extra';
import cleanCache from './cleanCache';
import startUp from '../../utils/startUp';
jest.mock('fs-extra', () => {
const emptyDir = jest.fn();
return { emptyDir };
});
jest.mock('../../utils/startUp');
beforeEach(() => {
fse.emptyDir.mockReset();
});
test('cleanCache', async () => {
const context = {};
await startUp({ context, options: {}, command: {} });
await cleanCache({ context });
expect(fse.emptyDir.mock.calls).toEqual([['baseDirectory/cacheDirectory']]);
});
test('cleanCache baseDir', async () => {
const context = {};
await startUp({ context, options: { baseDirectory: 'baseDir' }, command: {} });
await cleanCache({ context });
expect(fse.emptyDir.mock.calls).toEqual([['baseDir/cacheDirectory']]);
});

Some files were not shown because too many files have changed in this diff Show More